package com.itheimamobile.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.exception4project.NoSuchOrderSettingException;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetMeal;
import com.itheima.service.MobileOrderSettingService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class MobileOrderController {

    @Reference
    private MobileOrderSettingService mobileOrderSettingService;

    /**
     * 预约表单的提交
     *
     * @param map 预约信息
     * @return 预约结果
     */
    @RequestMapping("/addOrderSetMeal")
    public Result addOrderSetMeal(@RequestBody Map map) {
        // System.out.println(orderSetMeal);
        //调用service层的预约业务
        try {
            Integer id = mobileOrderSettingService.addOrderSetMealSetting(map);
            return new Result(true, MessageConstant.ORDER_SUCCESS, id);
        } catch (Exception ex) {
            ex.printStackTrace();
            if (ex instanceof NoSuchOrderSettingException)
                return new Result(false, ex.getMessage());
            else
                return new Result(false, "");
        }
    }

    @RequestMapping("/findById")
    public Result findByOrderId(Integer id) {

        Map orderInfo = mobileOrderSettingService.findById(id);
        return new Result(true, null, orderInfo);
    }
}